// Time Tracker by Eric Nadeau (nado18@gmail.com)
// Copyright (C) 2007 by Eric Nadeau
// Distributed under the terms of the GNU General Public License (see GPL.txt)

package view;

import java.awt.*;

import javax.swing.*;

/**
 * @author nado18@gmail.com, on Jan 5, 2006
 */
public class BooleanEditor extends DefaultCellEditor {
	private JCheckBox cb;
	private BooleanRenderer br;
	
	private BooleanEditor( JCheckBox cb ) {
		super( cb );
		cb.setHorizontalAlignment( JCheckBox.CENTER );
		this.cb = cb;
	}
	
	public BooleanEditor( BooleanRenderer br ) {
		this(new JCheckBox());
		this.br = br;
	}
	
	public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
		cb.setSelected( ((Boolean)value).booleanValue() );
		
		br.setColor(isSelected, row, cb);
		
		return cb;
	}
	
}
